<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/8
 * Time: 15:29
 */

namespace bgb\juhe;

use bgb\Http;

class Juhe
{

    use Http;

    protected $key;

    protected static $instance;

    const ID_CARD_QUERY_URL = 'http://op.juhe.cn/idcard/query'; //身份证实名认证

    public function __construct($key)
    {
        $this->key = $key;
    }

    /**
     * 单例方法
     * @param $key
     * @return $this
     */
    public static function getInstance($key)
    {
        $_key = md5($key);

        if (!isset(self::$instance[$_key])) {
            self::$instance[$_key] = new static($key);
        }

        return self::$instance[$_key];

    }

    /**
     * 身份证实名认证
     * @param $idCard string 身份证号
     * @param $realName string 真实姓名
     * @return mixed
     */
    public function idCardCheck($idCard, $realName)
    {
        return $this->getRequest(self::ID_CARD_QUERY_URL, [
            'key' => $this->key,
            'idcard' => (string)$idCard,
            'realname' => urlencode($realName)
        ]);
    }
}